package cn.beausoft.mybatis3.test;

import cn.beausoft.mybatis3.sqlbuild.keyword.CompareOperator;
import cn.beausoft.mybatis3.sqlbuild.keyword.Sort;
import cn.beausoft.mybatis3.sqlbuild.selector.Selector;
import cn.beausoft.mybatis3.test.dao.auto.FileResourceAutoDao;
import cn.beausoft.mybatis3.test.dao.auto.FileTypeAutoDao;
import cn.beausoft.mybatis3.test.entity.FileResource;
import cn.beausoft.mybatis3.test.entity.FileType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.beans.Introspector;
import java.util.List;

/**
 * Hello world!
 *
 */
@Controller
@ComponentScan(basePackages = "cn.beausoft.mybatis3.test")
@EnableAutoConfiguration
public class SampleController
{
    @Autowired
    private FileTypeAutoDao fileTypeAutoDao;
    @Autowired
    private FileResourceAutoDao fileResourceAutoDao;

    @GetMapping("/test")
    @ResponseBody
    public List<FileResource> selectTest() {
        Selector<FileResource> selector = new Selector<>();
        selector.join(FileTypeAutoDao.TABLE)
                .on(FileTypeAutoDao.id, CompareOperator.EQUAL , FileResourceAutoDao.resourceType)
                .on(FileTypeAutoDao.id, CompareOperator.EQUAL, 5).ok();
        selector.whereByTable(FileTypeAutoDao.id, 5).orderByTable(FileTypeAutoDao.id, Sort.ASC);
        return fileResourceAutoDao.select(selector);
    }

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}
